﻿#include "DoubleEditEntry.h"
#include "EntryDoubleSpinBox.h"

struct DoubleEditEntry::DoubleEditEntryPrivate {
    QPointer<EntryDoubleSpinBox> spinbox;
};

DoubleEditEntry::DoubleEditEntry(QWidget *parent) : EditEntry {parent} {
	p.reset(new DoubleEditEntryPrivate);
	initUi();
}

DoubleEditEntry::~DoubleEditEntry() { }

void DoubleEditEntry::setRange(double min, double max) {
    p->spinbox->setRange(min, max);
}

void DoubleEditEntry::setValue(double value) {
    if(!p->spinbox->hasFocus()) {
        p->spinbox->setValue(value);
    }
}

double DoubleEditEntry::value() const {
    return p->spinbox->value();
}

void DoubleEditEntry::initUi() {
    p->spinbox = new EntryDoubleSpinBox;
    addEditControll(p->spinbox);
    connect(p->spinbox.data(), &EntryDoubleSpinBox::editingFinished, [=] { emit valueChanged(value()); });
}
